<?php
namespace Home\Controller;
use Think\Controller;
class ServerLogController extends CommnController{
    public function __construct(){
        parent::__construct();
    }
    public function serverList(){
        $LogModel = M('admin_log', '', 'KEFU');
        $search = I('get.kefulog');
        if (!empty($search)) {
            $where['b.content|b.aid|a.name'] = array('like', '%' . $search . '%');
        }
        $tol = $LogModel->alias('b')->join('admin a on b.aid=a.id')->join('role c on a.role_id=c.id')->where($where)->count();
        $row = '15';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $data = $LogModel->alias('b')->join('admin a on b.aid=a.id')->join('role c on a.role_id=c.id')->field('b.*,a.name,c.name as role_name')->where($where)->order('b.id desc')->LIMIT($page->listfirst, $page->listRows)->select();
        foreach ($data as $k => $v) {
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }
        $this->assign(array(
            'list' => $data,
            'fpage' => $fpage,
            'tol' => $tol
        ));
        $this->display();
    }

    public function ajax($code, $result, $r = '')
    {
        if (empty($r)) {
            $this->ajaxReturn(['code' => $code, 'result' => $result]);
        } else {
            $this->ajaxReturn(['code' => $code, 'result' => $result]);
            return false;
        }
    }
}